package com.exmaple.jdbc;

import java.sql.*;

public class JDBCExample {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        //1.注册驱动
        Class.forName("com.mysql.cj.jdbc.Driver");
        //2.获取连接
        //2.1 url
        String url= "jdbc:mysql://localhost:3306/javawebdb";
        //2.2 用户名
        String username = "root";
        //2.3 密码
        String password="123456";
        Connection conn = DriverManager.getConnection(url, username, password);
        //3.定义SQL语句
        String sql ="SELECT  * FROM tb_brand";
        //4. 获取执行SQL对象
        Statement statement = conn.createStatement();
        //5.执行SQL
        ResultSet resultSet = statement.executeQuery(sql);
        //6.处理返回结果
        while (resultSet.next()){
            int id = resultSet.getInt("id");
            String brand_name = resultSet.getString("brand_name");
            String company_name = resultSet.getString("company_name");
            String description = resultSet.getString("description");
            System.out.println("id："+id+" ,brand_name:"+brand_name+" ,company_name:"+company_name+ " ,description:"+description);
        }
        //7.释放资源
        statement.close();
        conn.close();



    }
}
